package com.six.JacksonOperation;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.six.entity.Person;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * ClassName:JsonToJava
 * Package:com.six
 * Description
 *
 * @Author:@wenxueshi
 * @Create:2023/7/27 - 22:48
 * @Version:v1.0
 */
//JSON数组字符串-->Java对象数组
public class JsonToJava5 {

    public static void main(String[] args) throws IOException {
        String json = "[{\"name\":\"swx\",\"age\":18,\"skillsList\":[\"java\",\"python\",\"php\"]},{\"name\":\"博尔特\",\"age\":55,\"skillsList\":[\"短跑\",\"两百米跑\"]}]";
        ObjectMapper objectMapper = new ObjectMapper();
        Person[] person = objectMapper.readValue(json, Person[].class);
        //Person(name=swx, age=18, skillsList=[java, python, php])
        //Person(name=博尔特, age=55, skillsList=[短跑, 两百米跑])
        for (Person person1 : person) {
            System.out.println(person1);
        }
    }
}
